package com.matrix.draft.juc.day5;

import com.matrix.draft.juc.util.JucUtil;

import java.util.concurrent.CountDownLatch;

public class TestMultiLatchAwait {
    public static void main(String[] args) {
        CountDownLatch latch = new CountDownLatch(1);
        for (int i = 0; i < 100; i++) {
            int finalI = i;
            new Thread() {
                public int count = 0; // 统计每个线程执行了几次while?
                @Override
                public void run() {
                    try {
                        setName("Thread" + finalI); // 修改线程名
                        latch.await(); // 所有线程阻塞在这
                        while (true) {
                            JucUtil.sleep(3000); // 休眠3秒
                            System.out.println(Thread.currentThread().getName() + "------第"+(++count)+"个while");
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }.start();
        }
        // 解放
        JucUtil.sleep(1000);
        latch.countDown();
        System.err.println("解放了!!!");


    }
}
